package com.kkb.utils;

import com.kkb.bean.User;

import javax.servlet.http.HttpSession;

public class UserUtil {
    public static String getUserName(HttpSession session){
        return (String) session.getAttribute("adminUserName");
    }
    public static String getUserPhone(HttpSession session){
        User user = (User)session.getAttribute("userInfo");

        return user.getPhoneNumber() ;
    }

    /**
     * 保存用户手机号和验证码
     * @param session
     * @param userPhone
     * @param code
     */
    public static void setUserCode(HttpSession session , String userPhone,String code){
        session.setAttribute(userPhone,code);
    }

    public static String getUserCode(HttpSession session , String userPhone){
        return (String) session.getAttribute(userPhone);
    }

    /**
     * 获取session 的用户信息
     * @param session
     * @return User用户信息对象
     */
    public static User getUserInfo(HttpSession session){
        return (User) session.getAttribute("userInfo");
    }

    /**
     * 将用户信息保存到session
     * @param session
     * @param u user对象
     */
    public static void setUserInfo(HttpSession session,User u){
        session.setAttribute("userInfo",u);
    }

}
